home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / pbaseiv.zip / P4MSC002.TIP < prev    next >
Text File  |  1991-12-16  |  3KB  |  77 lines

  1. To time BASIC routines, I wrote PROFILE.BAS [see listing].
  2. The program runs a profiling subroutine that times up to 100
  3. elapsed repeats of any instruction.
  4.  
  5. To profile a program, copy the subroutine (lines 9000
  6. through 9250) to your own code. (Lines 1100-1999 are
  7. included here only to demonstrate the profiler.) Near the
  8. beginning of your program, dimension an array PFACCUM!(100),
  9. set PFPOINT% to 0, and execute GOSUB 9000 as PROFILE.BAS
  10. does at lines 1100 through 1200. Then, at strategic
  11. locations, set PFPOINT% to a number between 1 and 99, and
  12. execute GOSUB 9000. (See lines 1250 through 1600 for
  13. examples of these steps.) The profile numbers do not have to
  14. be in sequence.
  15.  
  16. To display results for profiled points, set PFPOINT% to 100
  17. or higher, and execute GOSUB 9000 as in line 1900. Once you
  18. have done that, any future calls to the profiler subroutine
  19. will be ignored.
  20.  
  21. Precision is limited to the smallest fractions of seconds
  22. that TIMER provides. Short sequences may run so fast that
  23. they won't show in the report. Therefore, to profile a
  24. single statement, you may have to insert it into a FOR loop
  25. that cycles at least 1000 times.
  26.  
  27. Gil Gagnon
  28. Mississauga, Ontario, Canada
  29.  
  30. Editor's note: Use the profiler's report to find where your
  31. code spends the bulk of its time. By optimizing the most
  32. heavily traveled sections, you'll gain the greatest speed
  33. advantage with the least amount of work.
  34.  
  35. Because PC clocks are imprecise, you may receive different
  36. results for the same program profiled twice in succession.
  37. For better accuracy, profile your code three or more times
  38. and average the reported values.
  39.  
  40. PROFILE.BAS (Use Alt-F to extract to a file)
  41.  
  42. ---- BEGIN LISTING ----
  43. 1100 DIM PFACCUM!(100)
  44. 1200 PFPOINT% = 0: GOSUB 9000
  45. 1250 PRINT "Test loop #1"
  46. 1300 FOR N = 1 TO 10000 : NEXT N
  47. 1400 PFPOINT% = 1: GOSUB 9000
  48. 1450 PRINT "Test loop #2"
  49. 1500 FOR N = 1 TO 5000 : NEXT N
  50. 1600 PFPOINT% = 2: GOSUB 9000
  51. 1900 PFPOINT% = 100: GOSUB 9000
  52. 1999 END
  53. 9000 IF PFFIRST% = 1 THEN GOTO 9050
  54. 9010 PFFIRST% = 1
  55. 9020 PFEND% = 0
  56. 9030 PFTIMELAST! = TIMER
  57. 9040 PFLBL$ = "Elapsed time for point"
  58. 9050 IF PFEND% <> 0 THEN GOTO 9250
  59. 9060 PFTIME! = TIMER
  60. 9070 IF PFPOINT% > 99 THEN PFPOINT% = 99
  61. 9080 PFACCUM!(PFPOINT%) = PFACCUM!(PFPOINT%) + PFTIME! - PFTIMELAST!
  62. 9090 PFTIMELAST! = PFTIME!
  63. 9100 IF PFPOINT% <> 99 THEN GOTO 9250
  64. 9110 PFEND% = 1
  65. 9120 FOR PFPOINT% = 1 TO 100
  66. 9130 IF PFACCUM!(PFPOINT%) = 0 GOTO 9140
  67. 9135 PRINT PFLBL$; PFPOINT%; ":"; PFACCUM!(PFPOINT%)
  68. 9140 NEXT PFPOINT%
  69. 9250 RETURN
  70. ---- END LISTING ----
  71.  
  72. Title: BASIC Profiles
  73. Category: MSC
  74. Issue date: Apr 1991
  75. Editor: Tom Swan
  76. Supplementary files: NONE
  77.